package newXgame.hall.object
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import newXgame.hall.object.background.GameListBackground;
	import newXgame.utils.ExScrollUtils;
	
	import org.dstart.draw.csuper.CSprite;
	import org.dstart.object.menulist.MenuList;

	public class GameListObject extends CSprite
	{
		private var bgList:GameListBackground;		//	背景
		private var mcList:MenuList;				//	菜单列表
		private var mcScrollH:ExScrollUtils;		//	竖向滑动条
		private var mcScrollW:ExScrollUtils;		//	横向滑动条
		private var mcMask:Sprite;					//	遮照层
		
		private var nowWidth:Number;
		private var nowHeight:Number;
		
		public function GameListObject()
		{
			mcMask = new Sprite();			
			bgList = new GameListBackground();
			mcList = new MenuList("GameList.xml", new Array("GameID", "ServerID", "GameName", "ServerName"));
			mcScrollH = new ExScrollUtils();
			mcScrollW = new ExScrollUtils();
			
			mcMask.x = mcList.x = this.bgList.x + 4;
			mcMask.y = mcList.y = this.bgList.y + 4;
			
			this._root.addChild(bgList);
			this._root.addChild(mcList);
			this._root.addChild(mcMask);
			this._root.addChild(mcScrollH);
			this._root.addChild(mcScrollW);
			
			mcScrollH.SetSprites(mcList, mcMask, true);
			mcScrollW.SetSprites(mcList, mcMask, false);
			
			mcScrollW.rotation = -90;			
			
			mcList.addEventListener(MenuList.DO_CLICK, onSelectMenu);
		}
		
		//	修改列表的大小	
		public function ChangeSize(ww:Number, hh:Number):void
		{
			this.nowWidth = ww;
			this.nowHeight = hh;
			
			this.bgList.ChangeSize(ww, hh);
			
			this.mcMask.graphics.clear();
			this.mcMask.graphics.beginFill(0xFFFFFF, 0);
			this.mcMask.graphics.drawRect(0, 0, ww - 10 - mcScrollH.width, hh - 10 - mcScrollH.width);
			this.mcMask.graphics.endFill();
			
			var wHotList:Number = this.mcMask.width - 10;
			var hHotList:Number = this.mcMask.height - 10;
			
			wHotList = (wHotList < this.mcList.menuWidth) ? this.mcList.menuWidth : wHotList;
			hHotList = (hHotList < this.mcList.menuHeight) ? this.mcList.menuHeight : hHotList;
			
			this.mcList.ShowHotSprite(wHotList, hHotList);
			
			this.mcScrollH.RushVisible();
			this.mcScrollW.RushVisible();
			
			if(this.mcScrollH.visible)
			{
				mcScrollH.ChangeHeight(hh - 8);
			}
			
			if(this.mcScrollW.visible)
			{
				mcScrollW.ChangeHeight(ww - 8 - mcScrollH.width);
			}
			else
			{
				mcScrollW.ChangeHeight(ww - 8);
			}
			
			mcScrollH.SetPlace(this.bgList.x + ww - mcScrollH.width - 4, this.bgList.y);
			mcScrollW.SetPlace(this.bgList.x, this.bgList.y + hh - 8);			
		}
		
		public function get objWidth():Number
		{
			return this.nowWidth; 
		}
		
		public function get objHeight():Number
		{
			return this.nowHeight;
		}
		
		private function onSelectMenu(e:Event):void
		{
			ChangeSize(objWidth, objHeight);
		}			
	}
}